package com.example.errorhandlingdemo;

import com.example.errorhandlingdemo.common.BizException;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class DemoController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello World!";
    }

    @PostMapping("/user")
    public String createUser(@RequestParam String name) {
        if (name == null || name.trim().isEmpty()) {
            throw new BizException(400, "用户名不能为空");
        }
        return "用户创建成功: " + name;
    }

    @GetMapping("/error")
    public String testError() {
        int i = 1 / 0;
        return "OK";
    }
}